package com.tianbo.elfii.client.common;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.sql.SQLException;
import java.sql.Statement;

import javax.imageio.ImageIO;
import javax.swing.*;

import com.tianbo.elfii.client.common.ElfiiCommonUtil.FeedBackType;

public class CalibrationDialog extends JPanel{

	public JButton confirmBtn;
	public JButton cancelBtn;
	
    BufferedImage bgImg = null;
    
    public String titleStr = "触控屏幕校正";
    public String tipStr = "请选择校正类型";
    public Font titleStrFont;
    
    public String fourPointStr = "四点校正";
    public String ninePointStr = "九点校正";
    
    public JRadioButton fourPointCal;
    public JRadioButton ninePointCal;
	
	public CalibrationDialog(){
		
		titleStrFont = new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,22);
	}
    
	
	public void init(int type){
		this.setLayout(null);
		initImg();
		initRaidoBtn(type);
		initBtn();
	}

	public void initImg(){
        File f;
        try {
            f=new File("resource-common/images/config/wlan/ss_03.png");
            bgImg=ImageIO.read(f);
            
        } catch(Exception e) {System.out.print(e);}
	}
	
	public void initRaidoBtn(int type){
		fourPointCal = new JRadioButton();
		ninePointCal = new JRadioButton();
		
		fourPointCal.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,16));
		ninePointCal.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,16));
		
//		fourPointCal.setText("四点校正");
//		ninePointCal.setText("九点校正");
		
		ImageIcon unselectedIcon = new ImageIcon("resource-common/images/level 04.png");
		ImageIcon selectedIcon = new ImageIcon("resource-common/images/level 05.png");
		
		fourPointCal.setIcon(unselectedIcon);
		fourPointCal.setSelectedIcon(selectedIcon);
		
		ninePointCal.setIcon(unselectedIcon);
		ninePointCal.setSelectedIcon(selectedIcon);
		
		fourPointCal.setContentAreaFilled(false);
		ninePointCal.setContentAreaFilled(false);
		
		this.add(fourPointCal);
		this.add(ninePointCal);
		
		fourPointCal.setBounds(150, 140, 120, 40);
		ninePointCal.setBounds(300, 140, 120, 40);

		
		ButtonGroup group = new ButtonGroup();
		
		group.add(fourPointCal);
		group.add(ninePointCal);
		
		
		if(type == 4){
			fourPointCal.setSelected(true);
		}
		else{
			ninePointCal.setSelected(true);
		}
		
		
		fourPointCal.addItemListener(new ItemListener(){
       	 public void itemStateChanged(ItemEvent e) {
       		 JRadioButton jop=(JRadioButton) e.getSource();
       		 
       		 if(jop.isSelected()){
                	
                ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
                	
       		 }
       	 }
		});
		
		ninePointCal.addItemListener(new ItemListener(){
	       	 public void itemStateChanged(ItemEvent e) {
	       		 JRadioButton jop=(JRadioButton) e.getSource();
	       		 
	       		 if(jop.isSelected()){
	                	
	                ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
	                	
	       		 }
	       	 }
	       });
	}
	
	public void initBtn(){
		confirmBtn = new JButton();
		cancelBtn = new JButton();
		
		confirmBtn.setIcon(new ImageIcon("resource-common/images/login/sssss06.png"));
		cancelBtn.setIcon(new ImageIcon("resource-common/images/login/sssss07.png"));
		
		cancelBtn.setContentAreaFilled(false);
		cancelBtn.setBorder(null);
		cancelBtn.setFocusPainted(false);
		
		confirmBtn.setContentAreaFilled(false);
		confirmBtn.setBorder(null);
		confirmBtn.setFocusPainted(false);

		confirmBtn.setBounds(100, 220, 141, 44);
		cancelBtn.setBounds(304, 220, 141, 44);
		
		this.add(confirmBtn);
		this.add(cancelBtn);
	}
	
	
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
      
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.drawImage(bgImg,null,0,0);

        g2.setColor(Color.white);
        
        
        g2.setFont(titleStrFont);
    
        g2.drawString(titleStr, 100, 55);
        
        g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,18));
        
        g2.drawString(tipStr, 210, 120);
        
        g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,14));
        
        g2.drawString(fourPointStr, 180, 165);
        g2.drawString(ninePointStr, 330, 165);
    }
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame w = new JFrame();
		w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		w.setUndecorated(true); //
		w.setSize(545, 272);
//		w.show();
		CalibrationDialog dialog = new CalibrationDialog();
		dialog.setBounds(0, 0, 545, 272);
		dialog.init(9);
		w.setContentPane(dialog);
		w.show();
	}

}

